package Oct_2020_BETA.part1;

import org.jetbrains.annotations.NotNull;
import org.junit.Test;

import java.io.File;

public class abs {
    static long C = 0;
    static int CS =0;

    public static void main(String[] args) {
        //ctrl+d复制一行陈列其下
        File file = new File("F:\\wudao");
        File file1=new File("C:\\Users\\tarena\\Desktop\\top");
        System.out.println("count length is " + search(file));
        System.out.println("count is "+CS);
        delete(file1);
    }

    public static long search(@NotNull File file) {

//        file.delete();//只能删除空的文件夹
//        System.out.println( file.list());
//        file.listFiles();

        File[] p = file.listFiles();
        for (File m :
                p)
            if (true == m.isFile()) {
                System.out.println(m.length());
                System.out.println(m.getName());
                C+=m.length();
                CS++;
            } else if (true == m.isDirectory()) {
                System.out.println("dir is " + m.getName());
                search(m);
            }else {
                return C;
            }
        return C;
    }
    public static void delete(File file){
        File[] p=file.listFiles();
        for (File m:p){
            if (true==m.isFile()){
                m.delete();
            }else if (true == m.isDirectory()){
                delete(m);
            }
        }
        file.delete();
    }

}
